/*
 * Copyright 2013 Nicholas Bilyk
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package jasper.model.elements;

/**
 * The complexType element defines a complex type. A complex type element is an XML element that contains other
 * elements and/or attributes.
 *
 * Parent elements: element, redefine, schema
 *
 * Source: http://www.w3schools.com/schema/el_complexType.asp
 *
 * @author nbilyk
 */
public class ComplexType extends SchemaNode {

	/**
	 * Optional. Specifies a unique ID for the element
	 */
	public String id;

	/**
	 * Optional. Specifies a name for the element.
	 */
	public String name;

	/**
	 * Optional. Specifies whether the complex type can be used in an instance document. True indicates that an
	 * element cannot use this complex type directly but must use a complex type derived from this complex
	 * type. Default is false.
	 */
	public Boolean _abstract;

	/**
	 * Optional. Specifies whether character data is allowed to appear between the child elements of this
	 * complexType element. Default is false. If a simpleContent element is a child element, the mixed attribute
	 * is not allowed!
	 */
	public Boolean mixed;

	/**
	 * Optional. Prevents a complex type that has a specified type of derivation from being used in place of this
	 * complex type. This value can contain #all or a list that is a subset of extension or restriction:
	 * extension - prevents complex types derived by extension
	 * restriction - prevents complex types derived by restriction
	 * #all - prevents all derived complex types
	 *
	 * @see ComplexTypeBlock
	 */
	public String block;

	/**
	 * Optional. Prevents a specified type of derivation of this complex type element. Can contain #all or a
	 * list that is a subset of extension or restriction.
	 *
	 * @see ComplexTypeBlock
	 */
	public String _final;

	@Override
	public void addChild(SchemaNode child) {
		if (mixed && (child instanceof SimpleContent)) throw new IllegalArgumentException("Cannot add a SimpleContent child if mixed is true.");
		super.addChild(child);
	}
}
